package com.dangz.dans.model.resp;

import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**
 * @author dangz
 * @since 2018/1/24 10:31
 */
public class TrainsInfo implements java.io.Serializable, Comparable<TrainsInfo> {
    private String startStationName;
    private String endStationName;
    private String endTime;
    private String takeTime;
    private String startTime;
    private String trainName;
    private List<JSONObject> seatBookingItems;

    public String getStartStationName() {
        return startStationName;
    }

    public void setStartStationName(String startStationName) {
        this.startStationName = startStationName;
    }

    public String getEndStationName() {
        return endStationName;
    }

    public void setEndStationName(String endStationName) {
        this.endStationName = endStationName;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getTakeTime() {
        return takeTime;
    }

    public void setTakeTime(String takeTime) {
        this.takeTime = takeTime;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getTrainName() {
        return trainName;
    }

    public void setTrainName(String trainName) {
        this.trainName = trainName;
    }

    public List<JSONObject> getSeatBookingItems() {
        return seatBookingItems;
    }

    public void setSeatBookingItems(List<JSONObject> seatBookingItems) {
        this.seatBookingItems = seatBookingItems;
    }

    @Override
    public int compareTo(TrainsInfo o) {
        if (timeCompare(this.getStartTime()) > timeCompare(o.getStartTime())) {
            return 1;
        } else if (timeCompare(this.getStartTime()) < timeCompare(o.getStartTime())){
            return -1;
        }
        return 0;
    }

    /**
     * 时间转换
     * @param time
     * @return
     */
    private Long timeCompare(String time){
        long s = Integer.parseInt(time.substring(0,time.indexOf(":"))) * 3600;    //小时
        s += Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":"))) * 60;    //分钟
        s += Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":")));    //秒
        return s;
    }
}
